package
{
	import com.controls.utils.WebUtils;
	import com.controls.utils.WebWindow;
	
	import flash.display.DisplayObject;
	import flash.display.DisplayObjectContainer;
	import flash.display.Sprite;
	import flash.events.MouseEvent;
	import flash.text.TextField;
	
	/**
	 * @author Frost.Yen    
	 * @E-mail 871979853@qq.com
	 * @create 2017-3-6 下午7:42:03
	 *
	 */
	public class WebTest extends Sprite
	{
		private var _t0:TextField = createText();
		private var _t1:TextField = createText();
		private var _t2:TextField = createText();
		private var _jsAlert:TextField = createButton("Alert");
		private var _jsOpen:TextField = createButton("Open");
		private var _jsURL:TextField = createButton("URL");
		public function WebTest()
		{
			var webWindow:WebWindow = new WebWindow("简书 - 创作你的创作.html");
			trace(webWindow.getBrowserName());
			
			addChildren(_t0,this,100,100);
			addChildren(_t1,this,100,130);
			addChildren(_t2,this,100,230);
			addChildren(_jsAlert,this,100,50);
			addChildren(_jsOpen,this,150,50);
			addChildren(_jsURL,this,200,50);
			this.addChild(_t0);
			this.addChild(_t1);
			this.addChild(_t2);
			this.addChild(_jsAlert);
			this.addChild(_jsOpen);
			this.addChild(_jsURL);
			_t0.appendText(WebUtils.BrowserAgent);
			
			_t1.appendText("是否是IE："+WebUtils.IsIE.toString()+ "\r\n"); 
			_t1.appendText("是否是Chrome："+WebUtils.IsChrome.toString()+ "\r\n"); 
			_t1.appendText("是否是FireFox："+WebUtils.IsMozilla.toString()+ "\r\n"); 
			_t1.appendText("是否是Safari："+WebUtils.IsSafari.toString()+ "\r\n"); 
			_t1.appendText("是否是Opera："+WebUtils.IsOpera.toString()+ "\r\n"); 
			_t1.appendText("浏览器类型："+WebUtils.BrowserMatch().browser+" 浏览器版本："+WebUtils.BrowserMatch().version + "\r\n"); 
			
			_t2.appendText("获取URL地址：" +WebUtils.Url + "\r\n"); 
			_t2.appendText("获取所有URL参数：" + WebUtils.QueryString + "\r\n"); 
			_t2.appendText("获取URL参数id=：" + WebUtils.Request("id") + "\r\n"); 
			_t2.appendText("获取锚点参数：" + WebUtils.Hash + "\r\n"); 
			_t2.appendText("cuplayer.com提示获取主机头：" + WebUtils.Host + "\r\n"); 
			_t2.appendText("获取访问协议：" + WebUtils.Protocol + "\r\n"); 
			_t2.appendText("获取访问端口：" + WebUtils.Port + "\r\n"); 
			_t2.appendText("cuplayer.com提示获取页面名称路径：" + WebUtils.PathAndName + "\r\n"); 
			_t2.appendText("页面编码：" + WebUtils.PageEncoding + "\r\n"); 
			
			_jsAlert.addEventListener(MouseEvent.CLICK,btnAlertClick); 
			_jsOpen.addEventListener(MouseEvent.CLICK,btnOpenClick); 
			_jsURL.addEventListener(MouseEvent.CLICK,btnUrlClick); 
			
			trace("Url:"+WebUtils.Url);
			trace("Href:"+WebUtils.Href);
			trace("Hash:"+WebUtils.Hash);
			trace("Port："+WebUtils.Port);
			trace("PathAndName："+WebUtils.PathAndName);
			trace("Pathname："+WebUtils.Pathname);
			trace("Search："+WebUtils.Search);
			trace("Host："+WebUtils.Host);
			trace("Protocol："+WebUtils.Protocol);
		}
		private function btnAlertClick(evt:MouseEvent):void 
		{ 
			WebUtils.Alert('cuplayer.com提示弹出JS对话框示例！'); 
		} 
		private function btnOpenClick(evt:MouseEvent):void 
		{ 
			WebUtils.Eval("javascript:window.open('http://www.baidu.com','newwindow')"); 
		} 
		private function btnUrlClick(evt:MouseEvent):void 
		{ 
			WebUtils.Redirect("简书 - 创作你的创作.html?id="+Math.ceil(Math.random()*999999)+"&cid=ok&page="+Math.ceil(Math.random()*10)+"#end"); 
		} 
		private function addChildren(child:DisplayObject,parent:DisplayObjectContainer,x:Number=0,y:Number=0):void
		{
			parent.addChild(child);
			child.x = x;
			child.y = y;
		}
		private function createText():TextField
		{
			var t:TextField = new TextField();
			t.autoSize  = "left";
			//t.wordWrap = true;
			return t;
		}
		private function createButton(label:String):TextField
		{
			var t:TextField = new TextField();
			t.autoSize  = "left";
			t.text = label;
			t.border = true;
			t.borderColor = 0xcccccc;
			t.background = true;
			t.backgroundColor = 0xFFFFFF;
			t.selectable = false;
			return t;
		}
	}
}